#!/bin/bash
# 定义数据库连接信息
MYSQL_HOST="node101"
MYSQL_PORT="3306"
MYSQL_USER="root"
MYSQL_PWD="123456"
MYSQL_DB="gmall_newproduct_warehouse"
HIVE_DB="gmall_newproduct_warehouse"
#
## 1. 导入最近上新表 ads_shop_newproduct
#sqoop export \
#  --connect jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DB} \
#  --username ${MYSQL_USER} \
#  --password ${MYSQL_PWD} \
#  --table ads_shop_newproduct \
#  --export-dir /user/spark/warehouse/${HIVE_DB}/ads_shop_newproduct \
#  --input-fields-terminated-by '\001' \
#  --input-lines-terminated-by '\n' \
#  --columns "dt,product_prc,product_title,product_code,cum_pay_30d" \
#  --update-mode allowinsert \
#  --update-key "dt,product_code"
#
## 2. 导入新品监控表 ads_newproduct_monitor
#sqoop export \
#  --connect jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DB} \
#  --username ${MYSQL_USER} \
#  --password ${MYSQL_PWD} \
#  --table ads_newproduct_monitor \
#  --export-dir /user/spark/warehouse/${HIVE_DB}/ads_newproduct_monitor \
#  --input-fields-terminated-by '\001' \
#  --input-lines-terminated-by '\n' \
#  --columns "dt,newproduct_count,cum_uv_count,cum_pv_count,cum_add_cart_uv,cum_add_cart_qty,cum_collect_uv,cum_pay_amt,cum_pay_qty,cum_pay_buyer_cnt,cum_collect_rate,cum_addcart_rate,cum_pay_rate,cum_refund_success_amt" \
#  --update-mode allowinsert \
#  --update-key "dt"
#
## 3. 导入新品全年复盘表 ads_newproduct_payment_calendar
#sqoop export \
#  --connect jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DB} \
#  --username ${MYSQL_USER} \
#  --password ${MYSQL_PWD} \
#  --table ads_newproduct_payment_calendar \
#  --export-dir /user/spark/warehouse/${HIVE_DB}/ads_newproduct_payment_calendar \
#  --input-fields-terminated-by '\001' \
#  --input-lines-terminated-by '\n' \
#  --columns "dt,year,month,day,sku_id,payment_amount" \
#  --update-mode allowinsert \
#  --update-key "dt,sku_id"

# 4. 导入新品列表 ads_newproduct_list
sqoop export \
  --connect jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DB} \
  --username ${MYSQL_USER} \
  --password ${MYSQL_PWD} \
  --table ads_newproduct_list \
  --export-dir /user/spark/warehouse/${HIVE_DB}/ads_newproduct_list \
  --input-fields-terminated-by '\001' \
  --input-lines-terminated-by '\n' \
  --columns "sku_id,product_tag,sku_type,cum_visit_uv,cum_visit_pv,cum_add_cart_qty,cum_add_cart_uv,cum_favorite_uv,cum_qty,cum_buyer_uv,cum_conversion_rate,cum_payment_amount,cum_refund_success_amount,newproduct_time" \
  --update-mode allowinsert \
  --update-key "product_tag,sku_type,newproduct_time"